#include"SystemHead.h"
// 无名管道
int main()
{
    int fd[2];
    if(pipe(fd)==-1)
    {
        perror("pipe");
    }

    pid_t pid;
    pid=fork();
    if(pid < 0)
    {
        perror("fork");
        exit(-1);
    }

    if(pid==0)   //child    
    {
        while(1)
        {
            printf("this is a child process\n");
            char *str="helloworld";
            write(fd[1],str,strlen(str));       //写端
            sleep(3);
        }
    }
    else         //parent
    {
        // fcntl(fd[0],F_SETFL,O_NONBLOCK);
        fcntl(fd[0],F_SETFL,0);
        while(1)
        {
            printf("this is a parent process\n");
            char str[100]={0};
            read(fd[0],str,sizeof(str));
            printf("read from child :%s\n",str);
            sleep(1);
        }
    }
    return 0;
}